# -*- coding: utf-8 -*-
# !/usr/bin/env python
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")
django.setup()
from utils.mysql_utils import query_to_list

def get_host_connect_info(host_ids):
    sql_parameter = []
    if host_ids:
        sql_fragment = "WHERE b.host_id IN (%s)" % ','.join(['%s'] * len(host_ids))
        sql_parameter = host_ids
    else:
        sql_fragment = ''

    sql = """
    SELECT b.host_id, b.host_ip,b.host_connection_port,
    b.host_connection_code,c.resource_user_name,c.resource_user_pass,c.resource_user_keyfile,b.host_nick
    FROM hosts_management b 
    LEFT JOIN resource_user c ON b.resource_user_ids = c.resource_user_ids AND c.resource_user_default = 1
    %s
    """ % sql_fragment
    data = query_to_list(sql, sql_parameter)

    return data